<template>
  <div class="view-container">
    <div class="main-content">
      <div class="list-container">
        <el-tabs
          v-model="activeName"
          @tab-click="handleClick"
        >
          <el-tab-pane
            label="配送商应收"
            name="distributeReceivableList"
          />
          <el-tab-pane
            label="终端应收"
            name="terminalReceivableList"
          />
          <el-tab-pane
            label="代理应收"
            name="agentReceivableList"
          />
          <el-tab-pane
            label="商销应收"
            name="sellerReceivableList"
          />
        </el-tabs>
        <component
          :is="activeName"
          ref="comp"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { defineAsyncComponent, reactive, toRefs } from 'vue'
import { useRoute, useRouter } from 'vue-router'

export default {
  components: {
    distributeReceivableList: defineAsyncComponent(() =>
      import('./distributeReceivableList.vue')
    ),
    terminalReceivableList: defineAsyncComponent(() =>
      import('./terminalReceivableList.vue')
    ),
    agentReceivableList: defineAsyncComponent(() =>
      import('./agentReceivableList.vue')
    ),
    sellerReceivableList: defineAsyncComponent(() =>
      import('./sellerReceivableList.vue')
    ),
  },
  setup(props, context) {
    const route = useRoute()
    const router = useRouter()
    var datas = reactive({
      activeName: route.query.tabs || 'distributeReceivableList',
      comp: null,
    })
    const handleClick = (tab, event) => {
      console.log(tab, event)
      router.push({
        name: 'saleReceivable',
        query: {
          tabs: tab.props.name,
        },
      })
    }
    const createCashDeposit = () => {
      datas.comp.handleCreate()
    }
    const createSuccess = () => {
      datas.comp.refreshList()
    }
    return {
      ...toRefs(datas),
      handleClick,
      createCashDeposit,
      createSuccess,
    }
  },
}
</script>

